package com.i360day.invoker.configuration;

import com.i360day.invoker.context.HttpInvokerContext;
import com.i360day.invoker.context.InvokerContext;
import com.i360day.invoker.http.InvokerClient;
import com.i360day.invoker.loadbalancer.HttpInvokerCloudLoadBalancerClient;
import com.i360day.invoker.request.HttpInvokerRequest;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(HttpInvokerAutoConfiguration.class)
public class HttpInvokerCloudAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public HttpInvokerContext httpInvokerContext() {
        return new InvokerContext();
    }

    @Bean
    @ConditionalOnMissingBean
    public HttpInvokerRequest defaultHttpInvokerClient(InvokerClient delegate, LoadBalancerClient loadBalancerClient) {
        return new HttpInvokerCloudLoadBalancerClient(delegate, loadBalancerClient);
    }
}
